home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / FROMUTS / UNIXLIB37B / src / c / memchr < prev    next >
Text File  |  1990-09-27  |  797b  |  42 lines

  1. #ifdef __STDC__
  2. static char sccs_id[] = "@(#) memchr.c 1.0 "__DATE__" HJR";
  3. #else
  4. static char sccs_id[] = "@(#) memchr.c 1.0 26/9/90 HJR";
  5. #endif
  6.  
  7. /* memchr.c (c) Copyright 1990 H.Rogers */
  8.  
  9. #include <string.h>
  10.  
  11. #ifdef __STDC__
  12. void *memchr(register const void *s,register int c,register size_t n)
  13. #else
  14. void *memchr(s,c,n)
  15. register const void *s;
  16. register int c;
  17. register size_t n;
  18. #endif
  19. {
  20. register unsigned char *_s = (unsigned char *)s;
  21.  
  22. while (n & 0x07)
  23.   {
  24.   n--;
  25.   if (*_s++ == c) { ret: return((void *)(--_s)); }
  26.   }
  27. n >>= 3; while (n)
  28.   {
  29.   n--;
  30.   if (*_s++ == c) goto ret;
  31.   if (*_s++ == c) goto ret;
  32.   if (*_s++ == c) goto ret;
  33.   if (*_s++ == c) goto ret;
  34.   if (*_s++ == c) goto ret;
  35.   if (*_s++ == c) goto ret;
  36.   if (*_s++ == c) goto ret;
  37.   if (*_s++ == c) goto ret;
  38.   }
  39.  
  40. return(0);
  41. }
  42.